using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace ICSharpCode.WinFormsUI.Docking
{
    /// <summary>
    /// Visual Studio 2005 theme (default theme).
    /// </summary>
    public class VS2003Theme : DockPanelThemeBase
    {
        /// <summary>
        /// Applies the specified theme to the dock panel.
        /// </summary>
        /// <param name="dockPanel">The dock panel.</param>
        public override void Apply(DockPanel dockPanel)
        {
            if (dockPanel == null)
            {
                throw new NullReferenceException("dockPanel");
            }

            Measures.SplitterSize = 4;
            dockPanel.Extender.DockPaneCaptionFactory = new VS2013DockPaneCaptionFactory();
            dockPanel.Extender.AutoHideStripFactory = new VS2013AutoHideStripFactory();
            dockPanel.Extender.AutoHideWindowFactory = new VS2013AutoHideWindowFactory();
            dockPanel.Extender.DockPaneStripFactory = new VS2013DockPaneStripFactory();
            dockPanel.Extender.DockPaneSplitterControlFactory = new VS2013DockPaneSplitterControlFactory();
            dockPanel.Extender.DockWindowSplitterControlFactory = new VS2013DockWindowSplitterControlFactory();
            dockPanel.Extender.DockWindowFactory = new VS2013DockWindowFactory();
            dockPanel.Extender.PaneIndicatorFactory = new VS2013PaneIndicatorFactory();
            dockPanel.Extender.PanelIndicatorFactory = new VS2013PanelIndicatorFactory();
            dockPanel.Extender.DockOutlineFactory = new VS2013DockOutlineFactory();
            dockPanel.Skin = CreateVisualStudio2003();
        }

        internal static DockPanelSkin CreateVisualStudio2003()
        {
            DockPanelSkin skin = new DockPanelSkin();

            Color TabBaseColor = Color.FromArgb(214, 219, 233);
            Color TabOtherColor = Color.FromArgb(214, 219, 233);
            Color TabActiveColor = SystemColors.Control;           

            Color ToolBaseColor = Color.FromArgb(214, 219, 233);
            Color ToolActiveColor = Color.FromArgb(51, 51, 255);
            
            skin.AutoHideStripSkin.DockStripGradient.StartColor = SystemColors.ControlLight;
            skin.AutoHideStripSkin.DockStripGradient.EndColor = SystemColors.ControlLight;
            skin.AutoHideStripSkin.TabGradient.TextColor = SystemColors.ControlDarkDark;

            //skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.StartColor = SystemColors.Control;
            //skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.EndColor = SystemColors.Control;
            //skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.StartColor = SystemColors.ControlLightLight;
            //skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.EndColor = SystemColors.ControlLightLight;
            //skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.StartColor = SystemColors.ControlLight;
            //skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.EndColor = SystemColors.ControlLight;

            skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.StartColor = TabBaseColor;
            skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.EndColor = TabBaseColor;
            skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.StartColor = TabActiveColor;
            skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.EndColor = TabActiveColor;
            skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.TextColor = SystemColors.ControlText;
            skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.StartColor = TabOtherColor;
            skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.EndColor = TabOtherColor;


            skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.StartColor = SystemColors.ControlLight;
            skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.EndColor = SystemColors.ControlLight;

            skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.StartColor = SystemColors.Control;
            skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.EndColor = SystemColors.Control;

            skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.StartColor = Color.Transparent;
            skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.EndColor = Color.Transparent;
            skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.TextColor = SystemColors.ControlDarkDark;

            skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.StartColor = SystemColors.GradientActiveCaption; 
            skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.EndColor = SystemColors.GradientActiveCaption; 
            //skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.LinearGradientMode = LinearGradientMode.Vertical;
            skin.DockPaneStripSkin.ToolWindowGradient.ActiveCaptionGradient.TextColor =  SystemColors.ActiveCaptionText;

            skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.StartColor = TabBaseColor;// SystemColors.GradientInactiveCaption;
            skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.EndColor = TabBaseColor;// SystemColors.InactiveCaption;
            //skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.LinearGradientMode = LinearGradientMode.Vertical;
            skin.DockPaneStripSkin.ToolWindowGradient.InactiveCaptionGradient.TextColor = SystemColors.InactiveCaptionText;

            return skin;
        }

        private class VS2013DockPaneSplitterControlFactory : DockPanelExtender.IDockPaneSplitterControlFactory
        {
            public DockPane.SplitterControlBase CreateSplitterControl(DockPane pane)
            {
                //return new DockPane.DefaultSplitterControl(pane);
                return new VS2003SplitterControl(pane);
            }
        }

        private class VS2013DockWindowSplitterControlFactory : DockPanelExtender.IDockWindowSplitterControlFactory
        {
            public SplitterBase CreateSplitterControl()
            {
                //return new DockWindow.DefaultSplitterControl();
                return new VS2013DockWindow.VS2013SplitterControl();
            }
        }

        private class VS2013DockWindowFactory : DockPanelExtender.IDockWindowFactory
        {
            public DockWindow CreateDockWindow(DockPanel dockPanel, DockState dockState)
            {
                return new VS2013DockWindow(dockPanel, dockState);
            }
        }

        private class VS2013DockPaneCaptionFactory : DockPanelExtender.IDockPaneCaptionFactory
        {
            public DockPaneCaptionBase CreateDockPaneCaption(DockPane pane)
            {
                return new VS2003DockPaneCaption(pane);
            }
        }

        private class VS2013DockPaneStripFactory : DockPanelExtender.IDockPaneStripFactory
        {
            public DockPaneStripBase CreateDockPaneStrip(DockPane pane)
            {
                return new VS2003DockPaneStrip(pane);
            }
        }

        private class VS2013AutoHideStripFactory : DockPanelExtender.IAutoHideStripFactory
        {
            public AutoHideStripBase CreateAutoHideStrip(DockPanel panel)
            {
                return new VS2003AutoHideStrip(panel);
            }
        }       

        private class VS2013AutoHideWindowFactory : DockPanelExtender.IAutoHideWindowFactory
        {
            public DockPanel.AutoHideWindowControl CreateAutoHideWindow(DockPanel panel)
            {
                //return new DockPanel.DefaultAutoHideWindowControl(panel);
                return new VS2003AutoHideWindowControl(panel);
            }
        }

        public class VS2013PaneIndicatorFactory : DockPanelExtender.IPaneIndicatorFactory
        {
            public DockPanel.IPaneIndicator CreatePaneIndicator()
            {
                return new DockPanel.DefaultPaneIndicator();
            }
        }

        public class VS2013PanelIndicatorFactory : DockPanelExtender.IPanelIndicatorFactory
        {
            public DockPanel.IPanelIndicator CreatePanelIndicator(System.Windows.Forms.DockStyle style)
            {
                return new DockPanel.DefaultPanelIndicator(style);
            }
        }

        public class VS2013DockOutlineFactory : DockPanelExtender.IDockOutlineFactory
        {
            public DockOutlineBase CreateDockOutline()
            {
                return new DockPanel.DefaultDockOutline();
            }
        }


    }   

}